home *** CD-ROM | disk | FTP | other *** search
- /* MicrosecondTrapTest.c */
- /*
- * MicrosecondTrapTest.c
- * Copyright © 1994 Apple Computer Inc.
- * This is a test of the Microsecond trap available on recent systems.
- * All it does is time a single mouse-click.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "MicrosecondTrap.h"
- #include "MicrosecondTrapTest.h"
-
-
- #ifndef FALSE
- #define FALSE 0
- #define TRUE 1
- #endif
-
- EventRecord gEventRecord;
-
- void ErrorExit(
- OSErr errorStatus,
- ConstStr255Param errorMsg
- );
-
- void
- main(
- #ifdef THINK_C
- int argc,
- char **argv
- #endif
- )
- {
- UnsignedWide start;
- UnsignedWide end;
- UnsignedWide elapsed;
- double elapsedDouble;
- Str255 work;
- short i;
- DialogPtr helloDialog;
-
- MaxApplZone();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0);
- for (i = 0; i < 3; i++)
- EventAvail(everyEvent, &gEventRecord);
- /* */
- if (MicrosecondTrapPresent() == FALSE)
- ErrorExit(unimpErr, "\pMicrosecond Trap is not supported");
- helloDialog = GetNewDialog(DLOG_Hello, NULL, (WindowPtr) -1);
- if (helloDialog == NULL)
- ErrorExit(resNotFound, "\pMissing dialog resource");
- DrawDialog(helloDialog);
- InitCursor();
- while (Button() == FALSE)
- ;
- Microseconds(&start);
- while (Button())
- ;
- Microseconds(&end);
- DisposeDialog(helloDialog);
- MicrosecondDelta(&start, &end, &elapsed);
- elapsedDouble = MicrosecondToDouble(&elapsed) / 1000000.0;
- sprintf((char *) &work[1], "%0.6lf", elapsedDouble);
- work[0] = strlen((char *) &work[1]);
- ParamText(work, "\p", "\p", "\p");
- NoteAlert(DLOG_Goodbye, NULL);
- ExitToShell();
- }
-
- void
- ErrorExit(
- OSErr errorStatus,
- ConstStr255Param errorMsg
- )
- {
- Str255 work;
-
- NumToString(errorStatus, work);
- ParamText(work, errorMsg, "\p", "\p");
- InitCursor();
- StopAlert(ALRT_Error, NULL);
- ExitToShell();
- }
-
-